package cn.zcj.studytest.ThrowData;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class Result<T> {
    private Boolean success;

    private T data;

    private String msg;

    public Result<T> ok(String msg) {
        return this.setSuccess(true).setMsg(msg);
    }

    public static <T> Result<T> ok(T data) {
        return new Result<T>().setSuccess(true).setMsg("请求成功").setData(data);
    }

    public Result<T> data(T data) {
        this.setData(data);
        return this;
    }

    public static <T> Result<T> fail(String msg, T data) {
        return new Result<T>().setSuccess(false).setMsg(msg).setData(data);
    }

    public static <T> Result<T> fail(String msg) {
        return fail(msg, null);
    }
}
